﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace docmgr.WinForm
{
    public partial class DepartmentOperation : Form
    {
        DataTable dep = null;


        BLL.Department depbll = new BLL.Department();
        public DepartmentOperation()
        {
            InitializeComponent();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));

        }
        public DepartmentOperation(string key)
        {
            InitializeComponent();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));


            dep = depbll.GetModel(key);
        }
        private void DepartmentOperation_Load(object sender, EventArgs e)
        {
            if(dep!=null)
            {
                Nametbx.Text = (String)dep.Rows[0]["Name"];
                Remarktbx.Text =dep.Rows[0]["Remark"].ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(Nametbx.Text==null)
            {
                MessageBox.Show("部门名称不能为空");
                return;
            }

            if(dep==null)
            {
                String sqlStr = String.Format("insert [Department] (Name,Remark) values ('{0}','{1}')", Nametbx.Text, Remarktbx.Text);
                SQLHelper.ExecuteSql(SQLHelper.connString, sqlStr);
            }
            else
            {
                dep.Rows[0]["Name"] = Nametbx.Text;
                dep.Rows[0]["Remark"] = Remarktbx.Text;
                depbll.Update(dep);
            }
            MessageBox.Show("操作成功！");
            this.Close();
        }
    }
}
